package com.qyc.Microservice.repository;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.qyc.Microservice.dto.pojo.User;

public interface UserRepository extends JpaRepository<User, Serializable>{
	
	//通过姓名和年龄查询//select * from user where name=? and age = ?;
	public User findByNameAndAge(String name,Integer age);
	
	public List<User> findByAge(Integer age,Pageable pageable);//注意这里分页是从0页开始的
	
	public User findFirstByOrderByAgeAsc();//对age字段进行升序，取第一条
	
	public List<User> findFirst3ByAge(Integer age,Sort sort);//取出与age匹配的前条信息
	
	@Query("from User u where u.name = ?1 and u.age = ?2") //因为我们的jpa底层应用了我们的Hibernate框架，里边有一个hql语句。
	public User getByNameAndAge(String name,Integer age);
	
	public User findByNameAndPassword(String name,String password);
	
	@Query("update User u set u.password=?3 where u.name=?1 and u.password = ?2")
	@Modifying
	@Transactional
	public void changePwd(String name,String oldPwd,String newPwd);
	
	public List<User> findByNameLike(String name);
}
